﻿@using Mangix.Admin.Framework.Menu
@using Mangix.Mapping.Category

@helper RenderMenuItem(CategoryMapping item, List<CategoryMapping> list)
{
string href = string.Empty;
if (!String.IsNullOrEmpty(item.RouteName))
{
    href = Url.RouteUrl(item.RouteName);
}
if (!String.IsNullOrEmpty(item.Controller) && !String.IsNullOrEmpty(item.Action))
{
    href = Url.Action(item.Action, item.Controller);
}
    <li>
        @{
            var childNodes = list.Where(o => o.FatherResource == item.SysResource && o.IsMenu).OrderBy(o => o.Name).ToList();
        }
        <a href="javascript:" data-href="@href" data-txt="@item.Name" data-id="@item.ResouceID" class="@(childNodes.Any()?"dropdown-toggle":"link-href")">
            <i class="@item.CssClass"></i>
            <span class="menu-text">@item.Name</span>
            @if (childNodes.Any())
            {
                <b class="arrow fa fa-angle-down"></b>
            }
        </a>
        <b class="arrow"></b>
        @if (childNodes.Any())
        {
            <ul class="submenu">
                @foreach (var childItem in childNodes)
                {
                    @RenderMenuItem(childItem, list)
                }
            </ul>
        }
    </li>
}
<div id="sidebar" class="sidebar responsive sidebar-fixed sidebar-scroll">
    <script>
        try { ace.settings.check('sidebar', 'fixed') } catch (e) { }
    </script>
    @{
        List<CategoryMapping> list = WorkContext.MyDescriperes;
        if (list != null)
        {
            var nodes = list.Where(o => String.IsNullOrEmpty(o.FatherResource)).Where(o => o.IsMenu).OrderBy(o => o.Sort).ThenBy(o => o.Name).ToList();
            <ul class="nav nav-list" style="margin-top:5px;">
                @if (nodes != null)
                {
                    foreach (var item in nodes)
                    {
                        @RenderMenuItem(item, list)
                    }
                }
            </ul>
        }
    }
    <div class="sidebar-toggle" id="sidebar-collapse">
        <i class="ace-icon fa fa-angle-double-left" data-icon1="ace-icon fa fa-angle-double-left" data-icon2="ace-icon fa fa-angle-double-right"></i>
    </div>

    <script type="text/javascript">
        $(function () {

        });
    </script>
</div>